<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::domain(env('WEB_ADMIN'))->group(function () {

	Route::get('login', 'LoginController@index')->name('login');
	Route::post('login', 'LoginController@login');

	/* 登录中间件 */
	Route::middleware('auth:admin')->group(function () {

		/*公共路由*/
		Route::get('/users', 'UtilController@users')->name('util.users');
		Route::get('/', 'DefaultController@index')->name('index');
		Route::get('logout', 'DefaultController@logout')->name('logout');

		Route::get('/util/checker', 'Mbr\MemberController@checker')->name('util.checker');//会员自动匹配
		Route::get('/util/charge', 'Acl\StaffController@charge')->name('util.charge');	//操作员自动匹配
		Route::get('/util/shops', 'Biz\ShopController@shops')->name('util.shops');

		/* 权限中间件 */
		Route::middleware('permission:admin')->group(function () {

			/* 系统 */
			Route::prefix('system')->name('system.')->group(function () {

				Route::get('permission', 'Acl\PermissionController@index')->name('permission.index');
				Route::get('permission/{id}/edit','Acl\PermissionController@edit')->name('permission.edit');
				Route::put('permission/{id}','Acl\PermissionController@update')->name('permission.update');
				Route::put('permission/change/{id}', 'Acl\PermissionController@change')->name('permission.change');

				Route::get('role', 'Acl\RoleController@index')->name('role.index');
				Route::get('role/{id}/edit','Acl\RoleController@edit')->name('role.edit');
				Route::put('role/{id}','Acl\RoleController@update')->name('role.update');

				Route::get('privilege', 'Acl\RoleController@privilege')->name('role.privilege');

				Route::resource('staff', 'Acl\StaffController')->except(['destroy']);//账号授权

				Route::resource('category', 'Mgt\CategoryController');//分类设置
				
				//根据父目录获取子目录
				Route::get('category/children/{pid}', 'Mgt\CategoryController@children')->name('category.children');

				Route::get('passwd', 'Acl\StaffController@passwd')->name('staff.passwd');//密码修改
				Route::put('passwd/{id}', 'Acl\StaffController@chgpwd')->name('staff.chgpwd');
				Route::put('staff/change/{id}', 'Acl\StaffController@change')->name('staff.change');//账号状态设置

			});


			/* 商户 */
			Route::prefix('merchant')->name('merchant.')->group(function () {

				Route::get('shop','Biz\ShopController@index')->name('shop.index');
				Route::get('shop/create','Biz\ShopController@create')->name('shop.create');
				Route::post('shop','Biz\ShopController@store')->name('shop.store');
				Route::get('shop/apply', 'Biz\ShopController@apply')->name('shop.apply');
				//Route::get('shop/ticket', 'Biz\TicketController@index')->name('shop.ticket');

				Route::get('product','Sku\ProductController@index')->name('product.index');
				Route::get('product/create','Sku\ProductController@create')->name('product.create');
				Route::post('product','Sku\ProductController@store')->name('product.store');
				Route::get('product/edit/{id}','Sku\ProductController@edit')->name('product.edit');
				Route::post('product/{id}','Sku\ProductController@update')->name('product.update');
				Route::get('product/sku','Sku\ProductController@sku')->name('product.sku');
			});

			/* 团队 */
			Route::prefix('team')->name('team.')->group(function () {
				Route::resource('member', 'Mbr\MemberController')->except(['destroy']);//会员

			});

			/* 营销 */
			Route::prefix('market')->name('market.')->group(function () {
				Route::get('coupon','Biz\CouponController@index')->name('coupon.index');
				Route::get('coupon/create','Biz\CouponController@create')->name('coupon.create');
			});


			/* 设置 */
			Route::prefix('setup')->name('setup.')->group(function () {

				Route::resource('branch', 'Mgt\BranchController');

			});
		});
	});

	/* 公共路由 */
	Route::get('/util/captcha', 'UtilController@captcha')->name('util.captcha');
	Route::get('/util/safecode', 'UtilController@safecode')->name('util.safecode');
	Route::get('/util/members', 'UtilController@members')->name('util.members');
	Route::get('/util/sales', 'UtilController@sales')->name('util.sales');
	Route::get('/util/changes', 'UtilController@changes')->name('util.changes');

	Route::get('/util/balance', 'UtilController@balance')->name('util.balance');
});
